package com.yunxiao.cloud.web.config;

/**
 * @description: DataSourceHolder
 * 上下文切换
 * @author: yunxiao
 * @date: 2020/1/20 9:25
 * @version: V1.0
 **/
public class DataSourceHolder {

    private static final ThreadLocal<String> DS_HOLDER = new ThreadLocal<>();

    private DataSourceHolder() {
        // Do nothing because of AOP
    }
    /**
     * 设置数据源
     * @param dataSource
     */
    public static void setDataSource(DataSourceEnum dataSource) {
        DS_HOLDER.set(dataSource.getName());
    }

    public static String getDataSource() {
        return DS_HOLDER.get();
    }

    public static void clearDataSource() {
        DS_HOLDER.remove();
    }
}
